
package net.lab0.fractal.classes;


import java.awt.geom.Point2D;


/**
 * @author 116
 */
public class ViewCoordinates
{
    private double xCenter;
    private double yCenter;
    private double width;
    private double height;
    
    public ViewCoordinates(double xCenter, double yCenter, double width, double height)
    {
        super();
        this.xCenter = xCenter;
        this.yCenter = yCenter;
        this.width = width;
        this.height = height;
    }
    
    public ViewCoordinates(ViewCoordinates coordinates)
    {
        this(coordinates.xCenter, coordinates.yCenter, coordinates.width, coordinates.height);
    }
    
    public synchronized double getxCenter()
    {
        return xCenter;
    }
    
    public synchronized double getyCenter()
    {
        return yCenter;
    }
    
    public synchronized double getWidth()
    {
        return width;
    }
    
    public synchronized double getHeight()
    {
        return height;
    }
    
    public synchronized void setxCenter(double xCenter)
    {
        this.xCenter = xCenter;
    }
    
    public synchronized void setyCenter(double yCenter)
    {
        this.yCenter = yCenter;
    }
    
    public synchronized void setWidth(double width)
    {
        this.width = width;
    }
    
    public synchronized void setHeight(double height)
    {
        this.height = height;
    }
    
    public synchronized void zoom(double quantity)
    {
        if (quantity > 0)
        {
            width *= quantity;
            height *= quantity;
        }
    }
    
    public double getViewScale()
    {
        return getWidth() / getHeight();
    }
    
    public Point2D.Double getTopLeftCorner()
    {
        return new Point2D.Double(xCenter - width / 2, yCenter + height / 2);
    }
    
    public Point2D.Double getTopRightCorner()
    {
        return new Point2D.Double(xCenter + width / 2, yCenter + height / 2);
    }
    
    public Point2D.Double getBottomLeftCorner()
    {
        return new Point2D.Double(xCenter - width / 2, yCenter - height / 2);
    }
    
    public Point2D.Double getBottomRightCorner()
    {
        return new Point2D.Double(xCenter + width / 2, yCenter - height / 2);
    }
    
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        long temp;
        temp = Double.doubleToLongBits(height);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(width);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(xCenter);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(yCenter);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
    
    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ViewCoordinates other = (ViewCoordinates) obj;
        if (Double.doubleToLongBits(height) != Double.doubleToLongBits(other.height))
            return false;
        if (Double.doubleToLongBits(width) != Double.doubleToLongBits(other.width))
            return false;
        if (Double.doubleToLongBits(xCenter) != Double.doubleToLongBits(other.xCenter))
            return false;
        if (Double.doubleToLongBits(yCenter) != Double.doubleToLongBits(other.yCenter))
            return false;
        return true;
    }

    @Override
    protected Object clone()
    throws CloneNotSupportedException
    {
        return new ViewCoordinates(this);
    }
}
